// $u.mixin.js

import {
	mapState,
	mapActions
} from 'vuex'
import store from "@/store"


module.exports = {
	beforeCreate() {
		// 将vuex方法挂在到$u中
		// 使用方法为：如果要修改vuex的state中的user.name变量为"史诗" => this.$u.vuex.set('user.name', '史诗')
		// 如果要修改vuex的state的version变量为1.0.1 => this.$u.vuex.set('version', '1.0.1')
		const vuex = {
			set: (name, value) => {
				this.$store.commit('$uStore', {
					name,
					value
				})
			},
			get: (name) => {
				let value = this.$u.func.getObjData(this.$store.state, name);
				if(typeof value === "undefined") return "";
				return JSON.parse(JSON.stringify(value));
			},
			
			dispatch: this.$store.dispatch,
			
			getters: (name) => this.$store.getters[name],
			
			actions: mapActions
		}
		uni.$u.vuex = vuex

	}
}
